package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public PageResult<Clazz> list(String name, LocalDate begin, LocalDate end, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        Page<Clazz> list = (Page<Clazz>) clazzMapper.list(name, begin, end);
        return new PageResult<>(list.getTotal(),list.getResult());
    }

    @Override
    public Clazz queryById(Integer id) {
        Clazz clazz = clazzMapper.queryById(id);
        return clazz;
    }

    @Override
    public void addClazz(Clazz clazz) {
        log.info("service增加部门:{}",clazz);
        clazzMapper.addClazz(clazz);
    }

    @Override
    public void updateClazz(Clazz clazz) {
        clazzMapper.updateClazz(clazz);
    }

    @Override
    public void deleteClazz(Integer id) {
        clazzMapper.deleteClazz(id);
    }

}
